package com.ets.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.table.JTableHeader;

public class VendorPanel extends JPanel 
{
	private static final long serialVersionUID = 1;	

	private JButton addButton,
	changeButton,
	exitButton;

	public VendorPanel()
	{
		// display panel
		setLayout(new GridBagLayout());

		Border loweredBorder
		= BorderFactory.createBevelBorder(BevelBorder.LOWERED);

		JPanel vendorDisplayPanel = new JPanel();

		vendorDisplayPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

		/*
vendorDAO = new UserDB();
vendors = vendorDAO.getUsers();
		 */
		Object[][] tempData = new Object[100][10];
		Object[][] data = tempData;
		/*
		 */
		String col[] = {"Vendor Number","Vendor Data1","Vendor Data2", "Vendor Data3","Vendor Data4"};
		/*
int m = 0;

for (User aa : users)
{
System.out.println(aa.getNmFst());
tempData[m][0] = aa.getUser();
tempData[m][1] = aa.getNmFst();
tempData[m][2] = aa.getNmMdl();
tempData[m][3] = aa.getNmLst();
tempData[m][4] = aa.getPhn1();
tempData[m][5] = aa.getPhn2();

System.out.println(tempData[m][0] + " " + tempData[m][1] + " " + tempData[m][2] + " " + tempData[m][3]);

m++;
}


		 */		
		JTable table = new JTable(data,col);
		/*
table.getColumnModel().getColumn(1).setPreferredWidth(200); 
table.getColumnModel().getColumn(2).setPreferredWidth(200); 
table.getColumnModel().getColumn(3).setPreferredWidth(200); 
table.getColumnModel().getColumn(4).setPreferredWidth(100); 
table.getColumnModel().getColumn(5).setPreferredWidth(100); 
		 */
		JTableHeader header = table.getTableHeader();
		header.setBackground(Color.red);
		table.setGridColor(Color.BLACK);
		/*
table.setBackground(Color.white);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		 */
		JScrollPane pane = new JScrollPane(table);

		//table.setBackground(getForeground());


		pane.setPreferredSize(new Dimension(800, 500)); 
		vendorDisplayPanel.add(pane);

		// button panel
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

		//Add button
		addButton = new JButton("Add Vendor");
		buttonPanel.add(addButton);
		addButton.setToolTipText("This is the add button");

		//Change button
		changeButton = new JButton("Change Vendor");
		buttonPanel.add(changeButton);
		changeButton.setToolTipText("This is the change button");

		//Exit button
		exitButton = new JButton("Exit");
		buttonPanel.add(exitButton);
		exitButton.setToolTipText("This is the exit button");


		this.add(vendorDisplayPanel, getConstraints(1,1,3,1, GridBagConstraints.CENTER));

		this.add(buttonPanel, getConstraints(1,2,3,1, GridBagConstraints.CENTER));
	}

	private void setResizable(boolean b) {
		// TODO Auto-generated method stub

	}

	private GridBagConstraints getConstraints(int gridx, int gridy,
			int gridwidth, int gridheight, int anchor)
	{
		GridBagConstraints c = new GridBagConstraints();
		c.insets = new Insets(5, 5, 5, 5);
		c.ipadx = 5;
		c.gridx = gridx;
		c.gridy = gridy;
		c.gridwidth = gridwidth;
		c.gridheight = gridheight;
		c.anchor = anchor;
		return c;
	}







}
